package com.aiwei.tdjk.service.impl;

import com.aiwei.tdjk.bean.Pager;
import com.aiwei.tdjk.dao.extend.CustomsRefinvstdExtendMapper;
import com.aiwei.tdjk.dto.request.CustomsRefinvstdPagerRequest;
import com.aiwei.tdjk.entity.CustomsRefinvstd;
import com.aiwei.tdjk.entity.CustomsRefinvstdExample;
import com.aiwei.tdjk.service.CustomsRefinvstdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomsRefinvstdServiceImpl implements CustomsRefinvstdService{

    @Autowired
    private CustomsRefinvstdExtendMapper customsRefinvstdExtendMapper;


    /**
     * 分页查询
     * @param request
     * @return
     */
    @Override
    public Pager<CustomsRefinvstd> find(CustomsRefinvstdPagerRequest request) {
        request.webParamConvert();
        List<CustomsRefinvstd> list = customsRefinvstdExtendMapper.find(request);
        int totalCount = customsRefinvstdExtendMapper.getTotalCount(request);
        Pager<CustomsRefinvstd> pager = new Pager<>();
        pager.setPageNumber(request.getPageNumber());
        pager.setPageSize(request.getPageSize());
        pager.setList(list);
        pager.setTotalCount(totalCount);
        return pager;
    }


    /**
     * 获取
     * @param id
     * @return
     */
    @Override
    public CustomsRefinvstd get(Long id){
        return customsRefinvstdExtendMapper.selectByPrimaryKey(id);
    }


    /**
     * 新增
     *
     * @param customsRefinvstd
     * @return
     */
    @Override
    public int add(CustomsRefinvstd customsRefinvstd) {
        return customsRefinvstdExtendMapper.insertSelective(customsRefinvstd);
    }

    /**
     * 更新
     *
     * @param customsRefinvstd
     */
    @Override
    public void update(CustomsRefinvstd customsRefinvstd) {
        customsRefinvstdExtendMapper.updateByPrimaryKeySelective(customsRefinvstd);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        customsRefinvstdExtendMapper.deleteByPrimaryKey(id);
    }


    @Override
    public String getCustomsStandardByInvStandard(String invStandard) {
        CustomsRefinvstdExample example = new CustomsRefinvstdExample();
        example.or().andInvStandardEqualTo(invStandard);
        List<CustomsRefinvstd> customsRefinvstds = customsRefinvstdExtendMapper.selectByExample(example);
        if (customsRefinvstds!=null&& customsRefinvstds.size()>0){
            return  customsRefinvstds.get(0).getCustomsStandard();
        }
        return null;
    }

}
